import {
	getMv,
	getMvDetail,
	getRelated,
	getTopMv
} from '../../service/api_video.js'

export default {
	namespaced: true,
	state: {
		videoLists: [],
		hasMore: true,
		offsets: 0,
		mvDetail: '',
		mvVideo: '',
		mvLists: []
	},
	mutations: {
		sendVideo(state, payload) {
			if (state.videoLists.length == 0 || state.offsets == 0) {
				state.videoLists = payload
			} else {
				state.videoLists.push(...payload)
			}
		},
		sendHasMore(state, payload) {
			state.hasMore = payload
		},
		sendOffse(state, payload) {
			state.offsets = payload
		},
		sendMvDetail(state, payload) {
			state.mvDetail = payload
		},
		sendMvVideo(state, payload) {
			state.mvVideo = payload
		},
		sendMvLists(state, payload) {
			state.mvLists = payload
		}
	},
	actions: {
		async fetchVideoData(context, payload) {
			await getTopMv(payload).then(res => {
				context.commit('sendOffse', payload)
				context.commit('sendVideo', res.data)
				context.commit('sendHasMore', res.hasMore)
			}).catch(error => {
				console.log(error);
			})
		},
		async fetchMvDeatil(context, payload) {
			await getMvDetail(payload).then(res => {
				context.commit('sendMvDetail', res.data)
			}).catch(error => {
				console.log(error);
			})
		},
		async fetchMvVideo(context, payload) {
			await getMv(payload).then(res => {
				context.commit('sendMvVideo', res.data)
			}).catch(error => {
				console.log(error);
			})
		},
		async fetchMvLists(context, payload) {
			await getRelated(payload).then(res => {
				context.commit('sendMvLists', res.data)
			}).catch(error => {
				console.log(error);
			})
		}
	}
}
